package com.ruoyi.project.student.service.imlp;

import com.ruoyi.project.student.domain.Student;
import com.ruoyi.project.student.domain.param.StudentParam;
import com.ruoyi.project.student.domain.vo.StudentListvo;
import com.ruoyi.project.student.mapper.StudentMapper;
import com.ruoyi.project.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServicelmpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public List<StudentListvo> selectStudentList(StudentParam param)
    {
        return studentMapper.selectStudentList(param);
    }
    @Override
    public int insertStudent(Student student)throws Exception
    {
        if (student.getName() == null || student.getName().equals("")){
            throw new Exception("姓名不能为空");
        }
        if (student.getNumber() == null || student.getNumber().equals("")){
            throw new Exception("学号不能为空");
        }
        int i=studentMapper.insertStudent(student);
        return i;
    }

    @Override
    public Student edit(Student student) throws Exception {
        Student target =studentMapper.selectById(student.getId());
        target.setName(student.getName());
        target.setNumber(student.getNumber());
       target.setClass_id(student.getClass_id());
        studentMapper.editStudentById(target);
        return target;
    }

    @Override
    public int delete(Student student) throws Exception {
        int i=studentMapper.delete(student.getId());
        return i;
    }
}
